#!/bin/bash

source="${1%.*}"
shift 1

if [ -z "${source}" ]
then
    1>&2 echo "usage:"
    1>&2 echo "  ${0} <source> [<option>]"
    exit 1
fi

set -ex
ffmpeg -y -i "${source}".mp4 -vf fps=10,scale=100:-1:flags=lanczos,palettegen "${source}"palette.png
ffmpeg -i "${source}".mp4 -i "${source}"palette.png -filter_complex "scale=100:-1:flags=lanczos[x];[x][1:v]paletteuse" "${source}".gif
